<?php

/**
 * @author aisyah
 * @copyright 2012
 */

require_once "../dao/product_dao.php";
require_once "../../app/dao/database.php";
require_once "../../config/upload_file.php";

$class_db = new Database;
$fupload = new Upload_File($dir);
$product = new Product_Dao($class_db);

$modul=$_GET['modul'];
$id=$_GET['id'];

switch($modul){
    
    case "hapus":    
        
        $query = $product->db->delete("product_detail"," productdet_id =".$id);
        
        if($query){
            header('location:product_view.php');
        }else{
            header('location:product_view.php?modul=detil&id='.$id);
        }
        
    
    break;
    
    case "ubah":
    
        $productdet_id = $_POST['id'];
        $product_name = $_POST['product_name'];
        $description = $_POST['description'];
        $price = $_POST['price'];              
        
        if(empty($_FILES['image']['tmp_name'])){
            
            $row = array('product_name'=>"$product_name",'description'=>"$description",
                    'price'=>"$price");
                    
                    
                    
        }else{
            $fupload->upload_file('produk','image');
            $image = $fupload->file_name;
            $thumbnail = $fupload->thumbnail;
            $row = array('product_name'=>"$product_name",'description'=>"$description",'image'=>"$image",
                    'thumbnail'=>"$thumbnail",'price'=>"$price");
                    
                }
        
        $update=$product->db->update('product_detail',$row,'productdet_id='.$productdet_id);
        if($update){
            header('location:product_view.php');
        }else{
            echo "gak berhasil update";
        }
        
    break;  
    
    
    
    }